home *** CD-ROM | disk | FTP | other *** search
-
- /* File : putimage.c */
- /* Entered by : A. Wayner */
- # include <graphics.h>
- # include <stdlib.h>
- # include <alloc.h>
-
- main()
- {
- int graphdriver = DETECT, graphmode;
- char far *image;
- char buffer[80];
- short x, y;
- unsigned numbytes, c= 0;
-
- /* Detect adapter type and initialize */
- /* graphics system */
- initgraph( &graphdriver, &graphmode, "\\turboc" );
-
- /* Draw a stick figure to animate */
- ellipse(5,5,0,360,5,5);
- setcolor(LIGHTCYAN);
- setfillstyle( SOLID_FILL, LIGHTCYAN);
- floodfill(5,5,MAGENTA);
-
- moveto(5,10);
- lineto(5,20);
- lineto(0,30);
-
- moveto(10,30);
- lineto(5,20);
-
- moveto(0,15);
- lineto(0,10);
- lineto(10,15);
-
- /* Determine storage needed for image */
- numbytes = (unsigned int ) imagesize( 0,0,10,30 );
-
- /* Allocate buffer for image */
- if( (image = (char far *) malloc (numbytes) ) == (char far * ) NULL )
- {
- closegraph();
- printf("Not enough memory for image storage \n");
- exit( 0 );
- }
-
- getimage( 0, 0, 10, 30, image ); /* save the image */
-
- /* Now clear screen and draw saved */
- /* image at several screen locations */
- cleardevice();
- setcolor( WHITE );
- outtextxy( 10, 10,"Demonstrating animation with putimage");
- x = getmaxx() / 2;
- y = getmaxy() / 2;
-
- putimage(x, y, image, XOR_PUT);
- outtextxy( 10, getmaxy() - 50,
- "q = exit, h = left, j = down, k = up, l = right");
-
-
- while( c != 'q' ) /* Perform some animation */
- {
- c = getch();
- putimage( x,y,image,XOR_PUT); /* First erase at last position */
-
- switch( c )
- {
- case 'h' : /* 2 pixels left */
- x -= 2;
- break;
- case 'l' : /* 2 pixels right */
- x += 2;
- break;
- case 'j' : /* 2 pixels down */
- y += 2;
- break;
- case 'k' : /* 2 pixels up */
- y -= 2;
- break;
-
- }
-
- putimage( x,y, image, XOR_PUT ); /* Redraw at new position */
-
- }
-
- closegraph(); /* Close graphics system when done */
- }
-
-